/*
 * Copyright (c) 2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef NEURAL_NETWORK_RUNTIME_NNEXECUTOR_H
#define NEURAL_NETWORK_RUNTIME_NNEXECUTOR_H

#include "executor.h"
#include "device.h"
#include "prepared_model.h"

namespace OHOS {
namespace NeuralNetworkRuntime {
class NNExecutor : public Executor {
public:
    NNExecutor(size_t deviceID,
               std::shared_ptr<Device> device,
               std::shared_ptr<PreparedModel> preparedModel,
               std::vector<std::shared_ptr<TensorDesc>> inputTensorDescs,
               std::vector<std::shared_ptr<TensorDesc>> outputTensorDescs);
    virtual ~NNExecutor() = default;

    virtual OH_NN_ReturnCode GetInputDimRange(size_t inputIndex,
                                              size_t** minInputDims,
                                              size_t** maxInputDims,
                                              size_t* shapeNum) const override;
    virtual OH_NN_ReturnCode GetOutputShape(uint32_t outputIndex, int32_t** shape, uint32_t* shapeNum) const override;

    virtual size_t GetInputNum() const override;
    virtual size_t GetOutputNum() const override;
    virtual NN_TensorDesc* CreateInputTensorDesc(size_t index) const override;
    virtual NN_TensorDesc* CreateOutputTensorDesc(size_t index) const override;

    virtual OH_NN_ReturnCode SetOnRunDone(NN_OnRunDone onRunDone) override;
    virtual OH_NN_ReturnCode SetOnServiceDied(NN_OnServiceDied onServiceDied) override;
    virtual OH_NN_ReturnCode RunSync(NN_Tensor* inputTensors[],
                                     size_t inputSize,
                                     NN_Tensor* outputTensors[],
                                     size_t outputSize) override;
    virtual OH_NN_ReturnCode RunAsync(NN_Tensor* inputTensors[],
                                      size_t inputSize,
                                      NN_Tensor* outputTensors[],
                                      size_t outputSize,
                                      int32_t timeout,
                                      void* userData) override;
    virtual size_t GetDeviceID() override;

private:
    OH_NN_ReturnCode CheckInputDimRanges(NN_Tensor* inputTensors[], size_t inputSize);

private:
    size_t m_deviceID {0};
    std::shared_ptr<Device> m_device {nullptr};
    std::shared_ptr<PreparedModel> m_preparedModel {nullptr};
    std::vector<std::shared_ptr<TensorDesc>> m_inputTensorDescs;
    std::vector<std::shared_ptr<TensorDesc>> m_outputTensorDescs;
    std::vector<std::vector<uint32_t>> m_minInputDims;
    std::vector<std::vector<uint32_t>> m_maxInputDims;
};
}  // namespace NeuralNetworkRuntime
}  // namespace OHOS
#endif  // NEURAL_NETWORK_RUNTIME_NNEXECUTOR_H
